<admintpl file="header" />
<style type="text/css">
.pic-list li {
	margin-bottom: 5px;
}
</style>
<script type="text/html" id="photos-item-wrapper">
    <li id="savedimage{id}">
        <input id="photo-{id}" type="hidden" name="pictures[]" value="{filepath}">
        <input id="photo-{id}-name" type="text" name="photos_alt[]" value="{name}" style="width: 160px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;" onclick="parent.image_preview_dialog(this.src);">
        <a href="javascript:upload_one_image('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#savedimage{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('AdminProduct/index')}">商品列表</a></li>
			<li class="active"><a href="{:U('AdminProduct/add',array('id'=>empty($item['id'])?'':$item['id']))}" target="_self">新增商品</a></li>
		</ul>
		<form action="{:U('AdminProduct/add_post')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th>选择分类</th>
							<td>
                                <select name="tid">
								<foreach name="type_list" item="titem">
                                    <option <if condition="$item['tid'] == $titem['id']">selected</if> value="{$titem.id}">
                                        {$titem.title}
                                    </option>
								</foreach>
                                </select>
								<span class="form-required">*</span>
							</td>
						</tr>
                        <tr>
                            <th>首页热门分类</th>
                            <td>
                                <select name="home_type">
                                    <option value="0">请选择</option>
                                    <option value="1" <if condition="$item['home_type'] == 1">selected</if>>首页热门分类-1</option>
                                    <option value="2" <if condition="$item['home_type'] == 2">selected</if> >首页热门分类-2</option>
                                </select>

                            </td>
                        </tr>
						<tr>
							<th>商品名称</th>
							<td><input type="text" name="pname" id="title" value="{$item.pname}" style="width: 400px" placeholder="请输入商品名称"> </td>
						</tr>
                        <tr>
                            <th>商品图片</th>
                            <td>
                                <ul id="pictures" class="pic-list unstyled">
                                    <foreach name="item['pictures']" item="vo">
                                        <li id="savedimage{$key}">
                                            <input id="photo-{$key}" type="hidden" name="pictures[]" value="{$vo}">
                                            <img id="photo-{$key}-preview" src="{:sp_get_image_preview_url($vo)}" style="height:36px;width: 36px;" onclick="parent.image_preview_dialog(this.src);">
                                            <a href="javascript:upload_one_image('图片上传','#photo-{$key}');">替换</a>
                                            <a href="javascript:(function(){ $('#savedimage{$key}').remove();})();">移除</a>
                                        </li>
                                    </foreach>
                                </ul>
                                <a href="javascript:upload_multi_image('图片上传','#pictures','photos-item-wrapper');" class="btn btn-small">选择图片</a>
                            </td>
                        </tr>
                        <tr>
                            <th>是否设置夏季常用药</th>
                            <td>
                                <input name="is_hot" type="radio" value="1" <if condition="$item.is_hot == 1">checked</if>/>&nbsp;是&nbsp;&nbsp;
                                <input name="is_hot" type="radio" value="0"  <if condition="$item.is_hot != 1">checked</if> />&nbsp;否
                            </td>
                        </tr>
                        <tr><th>是否推荐</th>
                            <td>
                                <input name="is_recommend" type="radio" value="1" <if condition="$item.is_recommend == 1">checked</if>/>&nbsp;是&nbsp;&nbsp;
                                <input name="is_recommend" type="radio" value="0" <if condition="$item.is_recommend != 1">checked</if>/>&nbsp;否
                            </td>
                        </tr>
                        <tr>
                            <th>内容</th>
                            <td>
                                <script type="text/plain" id="desc" name="desc">{$item.desc}</script>
                            </td>
                        </tr>

					</table>
				</div>

			</div>
			<div class="form-actions">
                <input type="hidden" name="id" value="{$item.id}"/>
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('AdminPost/index')}">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript">
        //编辑器路径定义
        var editorURL = GV.WEB_ROOT;
    </script>
    <script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript">
        $(function() {
            /////---------------------
            Wind.use('validate', 'ajaxForm', 'artDialog', function() {
                //javascript

                //编辑器
                editorcontent = new baidu.editor.ui.Editor();
                editorcontent.render('desc');
                try {
                    editorcontent.sync();
                } catch (err) {
                }
                //增加编辑器验证规则
                jQuery.validator.addMethod('editorcontent', function() {
                    try {
                        editorcontent.sync();
                    } catch (err) {
                    }
                    return editorcontent.hasContents();
                });
                var form = $('form.js-ajax-forms');
                //ie处理placeholder提交问题
                if ($.browser && $.browser.msie) {
                    form.find('[placeholder]').each(function() {
                        var input = $(this);
                        if (input.val() == input.attr('placeholder')) {
                            input.val('');
                        }
                    });
                }

            });
            ////-------------------------
        });
    </script>
	</body>
</html>